package com.teamb6.shop.service.impl;


import com.teamb6.shop.domain.*;
import com.teamb6.shop.mapper.IndentMapper;
import com.teamb6.shop.mapper.OrderItemMapper;
import com.teamb6.shop.service.IndentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class IndentServiceImpl implements IndentService {
    @Autowired(required = false)
    private IndentMapper indentMapper;
    @Autowired
    private OrderItemMapper orderItemMapper;
    @Override
    public List<Indent> findIsendIndent() {
        List<Indent> list = indentMapper.getAll();
        return list;
    }

    @Override
    public void delectIndentById(Integer indentid) {
        indentMapper.deleteByPrimaryKey(indentid);
    }

    //查询未发货订单商品
    @Override
    public SearchIndentResponse findgoods(Integer pageNum,Integer pageSize) {
        PageHelper.startPage(pageNum ,pageSize);
        List<Indent> indents = indentMapper.goodsAll();
        return new SearchIndentResponse(((Page)indents).getTotal(),indents);
    }
 //  修改发货信息
    @Override
    public int uodateIssent(Integer id) {
        int update =indentMapper.updateIssend(id);
        return update;
    }

    @Override
    public SearchIndentResponse searchIndent1(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum ,pageSize);
        List<Indent> indents = indentMapper.getAll1();
        return new SearchIndentResponse(((Page)indents).getTotal(),indents);
    }
    //未收货商品信息
    @Override
    public SearchIndentResponse findgoods1(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum ,pageSize);
        List<Indent> indents = indentMapper.goodsAll1();
        return new SearchIndentResponse(((Page)indents).getTotal(),indents);
    }

    @Override
    public void insertIndent(Indent order) {
        indentMapper.insertSelective(order);
    }

    @Override
    public void insertOrderItem(OrderItem orderItem) {
        orderItemMapper.insertSelective(orderItem);
    }

    @Override
    public void delectOrderItemByOrderid(Integer orderid) {
        OrderItemExample orderItemExample = new OrderItemExample();
        orderItemExample.or().andOrderidEqualTo(orderid);
        orderItemMapper.deleteByExample(orderItemExample);
    }

    @Override
    //查询未发货订单
    public SearchIndentResponse searchIndent(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum ,pageSize);
        List<Indent> indents=indentMapper.getAll();
        return new SearchIndentResponse(((Page)indents).getTotal(),indents);
    }
//    @Override
//    public SearchIndentResponse searchIndent(Integer pageNum , Integer pageSize){
//        PageHelper.startPage(pageNum,pageSize);
//        IndentExample indentExample = new IndentExample();
//        IndentExample.Criteria criteria = indentExample.createCriteria();
//        criteria.andIssendEqualTo(0);
//        List<Indent> list = indentMapper.selectByExample(indentExample);
//        return new SearchIndentResponse(((Page)list).getTotal(),list);
//
//    }


    @Override
    public List<Indent> selectIndentByExample(IndentExample example) {
        return indentMapper.selectByExample(example);
    }

    @Override
    public List<OrderItem> getOrderItemByExample(OrderItemExample orderItemExample) {
        return orderItemMapper.selectByExample(orderItemExample);
    }

    //根据订单id查询订单
    @Override
    public Indent selectByPrimaryKey(Integer orderid) {
        return indentMapper.selectByPrimaryKey(orderid);
    }

    //更新订单信息
    @Override
    public void updateIndentByKey(Indent indent) {
        indentMapper.updateByPrimaryKeySelective(indent);
    }
}
